
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
  <title>Demo</title>
  <style>
    *{      
      -webkit-touch-callout: auto; /* prevent callout to copy image, etc when tap to hold */      
      -webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */      
      -webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */       
      -webkit-user-select:none;
    }  
    html,body {
      width: 100%;
      height: 100%;
      padding: 0;
      margin: 0;
      max-width: 500px;
    }
    #paper {
      position: relative;
      overflow: hidden;
      width: 100%;
      padding-top: 75%;
      height: 0px;
    }
  </style>
</head>
<body>
  <div id="paper"></div>
  
  <script src="https://s2.ssl.qhres.com/!87edaa34/animator-0.3.1.min.js"></script>
  <script src="/js/spritejs.js"></script>

  <script>
const paper = spritejs.Paper2D('#paper'),
      fglayer = paper.layer('fglayer'),
      Sprite = spritejs.Sprite,
      Label = spritejs.Label  

paper.setResolution(1600, 1200) 

class Button extends Label {
  connect(parent, zOrder) {
    super.connect(parent, zOrder)

    this.on('mouseenter', evt => {
      this.attr({
        scale: 1.1
      })
    })

    this.on('mousedown', evt => {
      this.attr({
        scale: 0.95
      })
    })

    this.on('mouseup', evt => {
      this.attr({
        scale: 1.1
      })
    })

    this.on('mouseleave', evt => {
      this.attr({
        scale: 1.0
      })
    })
  }
}


// const button = new Button('Click Me')

// button.attr({
//   pos: [1350, 200],
//   font: '36px Arial',
//   color: '#000',
//   border: [1, '#000'],
//   borderRadius: 20,
//   padding: 25,
// })
// fglayer.appendChild(button) 


const birdsJsonUrl = '/images/birds.json'
const birdsRes = '/images/birds.png'

paper.preload([birdsRes, birdsJsonUrl])
.then(() => {
  const bird = new Sprite()
  bird.attr({
    textures: [
      'bird1.png'
    ],
    anchor: [0.5, 0.5],
    pos: [600, 600],
  })

  let i = 0
  setInterval(() => {
    bird.textures = `bird${++i % 2 + 1}.png`
  }, 100)

  fglayer.appendChild(bird)

  let animation = null

  // button.on('click', evt => {
  //   if(animation) animation.cancel()
  //   animation = bird.animate([
  //     {transform:{translate: [0, 0]}},
  //     {transform:{translate: [0, -100]}},
  //   ], {
  //     duration: 1000,
  //     iterations: Infinity,
  //     direction: 'alternate',
  //     easing: 'ease-in-out',
  //   })
  // })

  const label = new Label(`Render Box {x: ${bird.attr('x')} | y: ${bird.attr('y')}}`)
  label.attr({
    anchor: [0.5, 0.5],
    pos: [600, 300],
    font: '48px Arial',
    color: '#000',
    bgcolor: '#ddd',
  })

  fglayer.appendChild(label)

  bird.on('update', evt => {
    const [x, y] = bird.renderBox
    label.text = `Render Box {x: ${x} | y: ${y}}`
  })
})
  </script>
</body>
</html>


